<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="UTF-8">
    <title>编辑角色</title>
    <link rel="stylesheet" href="/static/dashboard.css">
    <link rel="stylesheet" href="/static/dashboard-theme.css">
</head>
<body>
    <div class="dashboard-container">
    {% include 'sidebar.html' %}
        <main class="main-content">
            <div class="header">
                <h2>编辑角色</h2>
                <a href="/logout/" class="logout">退出登录</a>
            </div>
            <section>
                <form method="post">
                    {% csrf_token %}
                    <div class="mb-3">
                        <label for="name" class="form-label">角色名称</label>
                        <input type="text" class="form-control" id="name" name="name" value="{{ role.name }}" required>
                    </div>
                    <div class="mb-3">
                        <label for="permissions" class="form-label">分配权限</label>
                        <select id="permissions" name="permissions" class="form-select" multiple>
                            {% for perm in permissions %}
                            <option value="{{ perm.id }}" {% if perm in role.permissions.all %}selected{% endif %}>{{ perm_cn|get_item:perm.codename|default:perm.name }} ({{ perm.codename }})</option>
                            {% endfor %}
                        </select>
                    </div>
                    <button type="submit" class="btn btn-primary">保存修改</button>
                    <a href="/roles/" class="btn btn-secondary ms-2">取消</a>
                </form>
            </section>
        </main>
    </div>
</body>
</html>
